<template>
  <div>
    <h1>添加用户需要客户自己注册......</h1>
  </div>
</template>
<!--<template>
  <div class="app-container">

    <h2 style="text-align: center;">添加用户</h2>

    <el-form>
      <el-form-item label="昵称">
        <el-input v-model="member.nickname" placeholder="请输入昵称"/>
      </el-form-item>

      <el-form-item label="手机号">
        <el-input v-model="member.mobile" placeholder="请输入手机号"/>
      </el-form-item>

      <el-form-item label="密码">
        <el-input v-model="member.password" placeholder="请输入密码"/>
      </el-form-item>

      <el-form-item label="性别">
        <el-input v-model="member.sex" placeholder="性别"/>
      </el-form-item>

      <el-form-item label="年龄">
        <el-input v-model="member.age" placeholder="年龄"/>
      </el-form-item>


      &lt;!&ndash; 课程封面 TODO &ndash;&gt;
      <el-form-item label="用户头像">

        <el-upload
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
          :action="BASE_API+'/eduoss/fileoss'"
          class="avatar-uploader">
          <img :src="member.avatar">
        </el-upload>

      </el-form-item>

      <el-form-item>
        <el-button :disabled="saveBtnDisabled" type="primary" @click="saveOrUpdate">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import user from "../../api/user";

export default {
  data() {
    return {
      saveBtnDisabled: false,
      member: {
        id: '',
        mobile: '',
        password: '',
        nickname: '',
        sex: '1',
        age: '18',
        avatar: 'https://guli-edu-1999.oss-cn-beijing.aliyuncs.com/2022/04/02/5094df7187f5482681b4935a52049e69109951163594594622.jpg',
        sign: '签名',
        isDeleted: 0
      },
      BASE_API: process.env.BASE_API, // 接口API地址
    }
  },
  created() {
    if (this.$route.params && this.$route.params.id) {
      const id = this.$route.params.id//从路径获取id值
      this.getInfo(id)//调用根据id查询的方法
    }
  },
  methods: {
    //上传封面成功调用的方法
    handleAvatarSuccess(res, file) {
      this.member.avatar = res.data.url
    },
    //上传之前调用的方法
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    },
    //添加
    addUserInfo() {
      user.addUser(this.member)
        .then(response => {
          //提示
          this.$message({
            type: 'success',
            message: '添加用户成功!'
          });
          //回到列表页面，路由跳转
          this.$router.push({path: "/user/list"})
        })
    },
    //根据id查询一条信息
    getInfo(id) {
      user.editUserById(id)
        .then(response => {
          this.member = response.data.userInfo
        })
    },
    //修改轮播图信息
    updateUserInfo() {
      user.editUser(this.member)
        .then(response => {
          //提示
          this.$message({
            type: 'success',
            message: '修改用户成功!'
          });
          //回到列表页面，路由跳转
          this.$router.push({path: "/user/list"})
        })
    },
    //保存或修改
    saveOrUpdate() {
      //判断是修改还是添加，如果有id是修改，没有id是添加
      if (!this.member.id) {
        this.addUserInfo()
      } else {
        this.updateUserInfo()
      }
    },
  }
}
</script>-->

